package com.example.coroutinedemo

import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.util.Log
import android.widget.ImageView
import com.example.coroutinedemo.then
import com.safframework.ext.*
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.coroutines.delay

class CoroutineMainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        button.click { startActivity(Intent(this, LoadingImageActivity().javaClass)) }
        button.setOnClickListener {
            startActivity(Intent(this, LoadingImageActivity().javaClass))
        }


        lifecycle_button.setOnClickListener {
            startActivity(Intent(this, LoadingImageLifecycleActivity().javaClass))
        }

        runOnAsyncThread {
            delay(6000)
            val value = true.then(test1(), false)
            Log.i("异步步线程", Thread.currentThread().name)
            "很漂亮"
        }.runMainThread {
            Log.i("主线程", Thread.currentThread().name)
        }
    }

    fun test1() {
        println("---------------->>")
    }
}
